/* ==============================================================================
 * 创 建 者：lyt
 * 创建日期：2017-07-14	
 * 功能描述：

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//挂卖
var SubmitUrl = baseUrl+'EPTradeF/SubmitSale';
//获取挂卖配置
var GetSetUrl =  baseUrl+'EPTradeF/SubmitSale';
//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';
//获取记录
var getListUrl = baseUrl+'EPTradeF/GetSelfSaleList';


var vu;
var mescroll;
$(function(){
	initVue();
});

function initVue(){
	vu = new Vue({
		el : '#content',
		data : {
			member : '',
			SetCoins : [],//转账币种
			ShowCoins : [],//显示币种
			chooseCoinIndex : 0,//选择币种
			
			selectedCoin : {//选择币种
				CoinOid : '',
				TransferMax : '',//最大值
				TransferMin : '',//最小值
				Radix : '',//基数
			},
			
			Count : '',
			CoinOID : '',
			
			
			pageIndex : 1,
			TotalPageCount : '',
			List : [],
		},
		mounted: function() {
			this.GetSet();
			this.getMemberView();
			initMescroll();
		},
		methods : {
			GetSet : GetSet,
			Submit : Submit,
			getMemberView : getMemberView,
			chooseCoin : chooseCoin,
		}
	})
}

function chooseCoin(){
	vu.selectedCoin = vu.SetCoins[vu.chooseCoinIndex];
}

function GetMemberName(){
	common.post(GetMemberNameUrl,{name : vu.TargetMemberName},'json',function(r){
		if(r.ErrorCode==0){
			vu.TargetMemberNiName = r.Data.NiName;
//			vu.CoinOID = r.Data.SetCoins[0].CoinOid;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

function getList(){
	common.get(getListUrl,{pageIndex: vu.pageIndex,pageSize: 10,},'json',function(r){
		if(r.ErrorCode==0){
			vu.TotalPageCount = r.Data.TotalPageCount;
			mescroll.endByPage(r.Data.TotalItemCount, vu.TotalPageCount);
			if(vu.pageIndex == 1){
				vu.List = r.Data.List;
			}else{
				vu.List = vu.List.concat(r.Data.List);
			}
			vu.pageIndex++;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

function initMescroll(){
	mescroll = new MeScroll("mescroll", {
		down:{
			use: false, //是否初始化下拉刷新; 默认true
			callback: function(mescroll) {
				vu.pageIndex = 1;
				mescroll.resetUpScroll();
				getList();
			}
		},
		up: {
			auto: true,
			isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
			clearEmptyId: "dataList", //1.下拉刷新时会自动先清空此列表,再加入数据; 2.无任何数据时会在此列表自动提示空
			toTop:{ //配置回到顶部按钮
				src : "phoneContent/img/top.png", //默认滚动到1000px显示,可配置offset修改
				//offset : 1000
			},
			htmlNodata: '<p class="upwarp-nodata">-- 没有更多数据了 --</p>', //无数据的布局
			callback: function (){//上拉回调
				getList();
			},
			page : {
				size : 10, 
			},
		}
	})
}

function Submit(){
	if(!vu.selectedCoin.CoinOid){
		mui.toast("请选择币种");
		return;
	}
	if(!vu.Count){
		mui.toast("请输入挂卖金额");
		return;
	}
	var btnArray = ['取消', '确定'];
	mui.prompt('', '', '请输入安全密码：', btnArray, function(e) {
		if(!e.value){
			mui.toast('请输入安全密码！');
			return;
		}
        if (e.index == 1) {
            common.post(SubmitUrl,{CoinOID : vu.selectedCoin.CoinOid,Count : vu.Count, SecondPwd : e.value},'json',function(r){
				if(r.ErrorCode==0){
					mui.toast(r.ErrorMsg);
					
					vu.Count = '';
					
					GetSet();
					vu.pageIndex = 1;
					mescroll.resetUpScroll();
					getList();
				}else{
					mui.toast(r.ErrorMsg);
				}
			})
        } 
    },'div')
	document.querySelector('.mui-popup-input input').type='password';
}

function GetSet(){
	common.get(GetSetUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.SetCoins = r.Data.SetCoins;
			vu.ShowCoins = r.Data.ShowCoins;
			if(vu.SetCoins.length){
				vu.selectedCoin = vu.SetCoins[0];
			}
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

